package com.goscom.app.deeset;

import com.goscom.app.database.DBAdapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

public class ExistingMerchandiser extends Activity {

	private EditText mEdtUniqueID;
	private String strMerId = "";
	private DBAdapter mDB;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Window window = getWindow();
		window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		setContentView(R.layout.existingmerchandier);

		mEdtUniqueID = (EditText) findViewById(R.id.edtExistUniqueID);

		mDB = new DBAdapter(ExistingMerchandiser.this);
		mDB.open();
	}

	public void Logout(View v) {
		if (mDB != null) {
			mDB.close();
		}
		startActivity(new Intent(ExistingMerchandiser.this, Login.class));
	}

	public void goSections(View v) {
		strMerId = mEdtUniqueID.getText().toString();
		if (strMerId.equals("")) {
			Toast.makeText(ExistingMerchandiser.this,
					"Please fill Digit Unique ID!", Toast.LENGTH_LONG).show();
		} else {
			if (mDB.queryMerchandiser("MER", strMerId) == 0) {
				Toast.makeText(ExistingMerchandiser.this,
						"Digit Unique ID not exist! Please check again!",
						Toast.LENGTH_LONG).show();
			} else {
				if (mDB != null) {
					mDB.close();
				}
				startActivity(new Intent(ExistingMerchandiser.this,
						MerchandiserName.class).putExtra("merid", strMerId));
			}
		}
	}

	public void sentMailtoHR(View v) {
		strMerId = mEdtUniqueID.getText().toString();
		if (strMerId.equals("")) {
			Toast.makeText(ExistingMerchandiser.this,
					"Please fill Digit Unique ID!", Toast.LENGTH_LONG).show();
		} else {
			if (mDB.queryMerchandiser("MER", strMerId) == 0) {
				Toast.makeText(ExistingMerchandiser.this,
						"Digit Unique ID not exist! Please check again!",
						Toast.LENGTH_LONG).show();
			} else {
				ConnectionDetector connectDetector = new ConnectionDetector(
						this);
				if (!connectDetector.isConnectingToInternet()) {
					connectDetector.showSettingsAlert();
				} else {
					startActivity(new Intent(this, UploadData.class).putExtra(
							"merid", strMerId));
				}
			}
		}
	}

	@Override
	protected void onRestart() {
		mDB.open();
		super.onRestart();
	}

	@Override
	protected void onDestroy() {
		if (mDB != null) {
			mDB.close();
		}
		super.onDestroy();
	}
}
